package top.lixunda.ecommerce.server.good.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.good.api.entity.db.GoodPictureDO;
import top.lixunda.ecommerce.server.good.api.entity.vo.GoodPictureVO;
import top.lixunda.ecommerce.server.good.api.controller.IGoodPictureController;
import top.lixunda.ecommerce.server.good.service.IGoodPictureService;

import java.util.List;

/**
 * 商品图片管理接口
 *
 * @author Xumda
 * @version time:2020/1/15 15:39
 */
@Slf4j
@RestController
public class GoodPictureController extends BaseController implements IGoodPictureController {

    private final IGoodPictureService goodPictureService;

    @Autowired
    public GoodPictureController(IGoodPictureService goodPictureService) {
        this.goodPictureService = goodPictureService;
    }

    /**
     * 根据图片id获取图片信息
     *
     * @param id 图片保存的id
     * @return 图片信息
     */
    @Override
    public MessageObject<GoodPictureVO> queryById(Integer id) {
        GoodPictureDO goodPictureDO = goodPictureService.queryById(id);
        GoodPictureVO goodPictureVO = GoodPictureVO.fromGoodPictureDO(goodPictureDO);
        return getSuccessMessageObject("获取数据成功", goodPictureVO);
    }

    /**
     * 根据商品id获取图片信息
     *
     * @param id 图片保存的id
     * @return 图片信息
     */
    @Override
    public MessageObject<List<GoodPictureVO>> queryByGoodId(Integer id) {
        List<GoodPictureDO> list = goodPictureService.queryByGoodId(id);
        List<GoodPictureVO> resultList = GoodPictureVO.fromGoodPictureDO(list);
        return getSuccessMessageObject("获取数据成功", resultList);
    }

}
